package com.newbee.boot.provider.controller;

import com.newbee.boot.provider.entity.User;
import com.newbee.boot.provider.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    private static final Logger LOGGER= LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserRepository userRepository;

    @GetMapping("/user/{id}")
    public User findById(@PathVariable("id") Long id) {
        //orElse 如果存在user则返回user，否则返回null
        LOGGER.info("被消费者调用了....");
        return userRepository.findById(id).orElse(null);
    }
}
